package com.shawn.jetpackstady.paging;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.shawn.jetpackstady.R;
import com.shawn.jetpackstady.paging.adapter.RecyclerAdapter;

public class PagingActivity extends AppCompatActivity {
    RecyclerView rv_paging;

    RecyclerAdapter recyclerAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paging);
        rv_paging = findViewById(R.id.rv_paging);
        recyclerAdapter = new RecyclerAdapter();
//        ConcertViewModel concertViewModel =
//                ViewModelProviders.of(this).get(ConcertViewModel.class);// 过时方法
        ConcertViewModel concertViewModel = new ViewModelProvider(this).get(ConcertViewModel.class);
        concertViewModel.getConvertList().observe(this, concerts -> {
            recyclerAdapter.submitList(concerts);
        });
        rv_paging.setAdapter(recyclerAdapter);
        rv_paging.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
//        rv_paging.addItemDecoration(new SimpleDividerDecoration(this));
    }
}
